public function go($content = '') {
    
-       // echo '这是来自php的数据';
    
-       $data = $this->input->post('content');
    
-       $data = $this->yd->translate($data);
    
-       echo $data;
 
+       $data = $this->yd->translate($this->input->post('content'));
 
+
 
+       echo $this->yd->ydTransToStr($data);
     
    }
     
 }
     
  
codeignite/application/models/YouDao_model.php 查看文件 @ 0bfb10f
@@ -20,7 +20,7 @@ class Youdao_model extends CI_Model {
     
        );
     
        $args['sign'] = $this->buildSign($this->appkey, $query, $args['salt'], $this->seckey);
     
        $ret          = $this->call($this->url, $args);
    
-       echo $ret;
 
+       // echo $ret;
     
        $ret = json_decode($ret, true);
     
        return $ret;
     
    }
@@ -97,4 +97,25 @@ class Youdao_model extends CI_Model {
     
        return $args;
     
    }
     
  
 
+   /**
 
+    * 将有道智云返回的数组中必要的信息整理成字符串
 
+    * @param  array $result 有道智云api返回的数组
 
+    * @return string        根据输入内容的类型，返回单词的解释或者长句的翻译
 
+    */
 
+   public function ydTransToStr($result) {
 
+
 
+       // http://ai.youdao.com/docs/doc-trans-api.s#p03
 
+       if (isset($result['basic']['explains'])) {
 
+           $str = '';
 
+           foreach ($result['basic']['explains'] as $key => $value) {
 
+               $str .= "<p>" . $value . "</p>";
 
+           }
 
+           return $str;
 
+       } elseif (isset($result['translation'])) {
 
+           return $result['translation'][0];
 
+       } else {
 
+           return '没查到';
 
+       }
 
+
 
+   }
     
 }